//! \file QueueList_TODO.h
//! \brief Defines the <code>fullsail_ai::data_structures::QueueList</code> class template
//! implementation.
//! \author Cromwell D. Enage
#ifndef _FULLSAIL_AI_FUNDAMENTALS_QUEUELIST_TODO_H_
#define _FULLSAIL_AI_FUNDAMENTALS_QUEUELIST_TODO_H_

namespace fullsail_ai { namespace fundamentals {

	//! \todo
	//!   - Complete the definition of the <code>QueueList::Iterator</code> pre-increment operator.
	//!   - Complete the definition of the <code>QueueList::Iterator</code> dereference operator.
	//!   - Define the <code>QueueList</code> constructor.
	//!   - Define the <code>QueueList</code> destructor.
	//!   - Define the <code>QueueList</code> methods.

	template <typename T>
	QueueList<T>::QueueList() : front(0), back(0)
	{
	}

	template <typename T>
	QueueList<T>::~QueueList()
	{
		removeAll();
	}

	template <typename T>
	bool QueueList<T>::isEmpty() const
	{
		if(front)
		{
			return false;
		}

		return true;
	}

	template <typename T>
	void QueueList<T>::enqueue(T element)
	{
		Node* temp = new Node(element);

		if(front)
		{
			back->next = temp;
			back = temp;
		}
		else
		{
			front = temp;
			back = temp;
		}
	}

	template <typename T>
	T QueueList<T>::getFront() const
	{
		return front->data;
	}

	template <typename T>
	void QueueList<T>::dequeue()
	{
		if(front == back)
		{
			Node* temp = front;
			front = NULL;
			back = NULL;
			delete temp;
		}
		else
		{
			Node* temp = front;
			front = front->next;
			delete temp;
		}
	}

	template <typename T>
	void QueueList<T>::removeAll()
	{
		while(front)
		{
			Node* temp = front;
			front = front->next;
			delete temp;
		}

		back = NULL;
	}

	template <typename T>
	bool QueueList<T>::contains(T element) const
	{
		Node* iter = front;

		while(iter)
		{
			if(iter->data == element)
			{
				return true;
			}

			iter = iter->next;
		}

		return false;
	}

	template <typename T>
	void QueueList<T>::remove(T element)
	{
		if(front->data == element)
		{
			dequeue();
			return;
		}

		Node* iter = front;

		while(iter->next)
		{
			if(iter->next->data == element)
			{
				if(iter->next == back)
				{
					back = iter;
					delete iter->next;
					iter->next = NULL;
					return;
				}
				else
				{
					Node* temp = iter->next;
					iter->next = iter->next->next;
					delete temp;
					return;
				}
			}

			iter = iter->next;
		}
	}


	template <typename T>
	typename QueueList<T>::Iterator& QueueList<T>::Iterator::operator++()
	{
		// TODO: Complete the definition of this operator.
		if(currentNode)
		{
			currentNode = currentNode->next;
		}

		return *this;
	}

	template <typename T>
	T QueueList<T>::Iterator::operator*() const
	{
		// TODO: Complete the definition of this operator.
		return currentNode->data;
	}


}}  // namespace fullsail_ai::fundamentals

#endif  // _FULLSAIL_AI_FUNDAMENTALS_QUEUELIST_TODO_H_

